package cn.wolfcode.lww.controller;

import cn.wolfcode.lww.domain.Hotsell;
import cn.wolfcode.lww.domain.Strategy;
import cn.wolfcode.lww.domain.User;
import cn.wolfcode.lww.service.UserService;
import cn.wolfcode.lww.service.impl.HotSellServiceImpl;
import cn.wolfcode.lww.service.impl.StrategyServiceImpl;
import cn.wolfcode.lww.service.impl.UserServiceImpl;
import cn.wolfcode.lww.util.QueryObject;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class UserController {
@Autowired
    UserServiceImpl userService;
@Autowired
    StrategyServiceImpl strategyService;
@Autowired
    HotSellServiceImpl hotSellService;

@RequestMapping("/login")
    public String login(User user, HttpSession session){
    User user1 = userService.selectByUsernameAndPassword(user);
    if (user!=null){
        session.setAttribute("user",user1);
        return "index/index";
    }else {
        return "public/login";
    }

}
@RequestMapping("/loginView")
public String loginView(){
    return "public/login";
}

@RequestMapping("/index")
    public String index(String searchTarget, String searchText, Model model, QueryObject queryObject){

    return "index/index";
}
@RequestMapping("loginOut")
    public String loginOut(HttpSession session){
    session.removeAttribute("user");
    return "public/login";
}
@RequestMapping("register")
    public String register(){
    return "public/register";
}
@RequestMapping("registerUser")
    public String registerUser(String username,String password){
    User user = new User();
    user.setPassword(password);
    user.setUsername(username);

    userService.insert(user);
    return "public/login";

}
}

